﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using MapCenterSystem.DataInfo;
using MapCenterSystem.DefineType;
using MapCenterSystem.Utility;
using MobiMap_Service.Models;
using MapCenterSytem.Process;

namespace MobiMap_Service.Controllers
{
    public class MapApiServiceController : ApiController
    {
        MapHandler mapHandler = new MapHandler();

        public NearPlace GetService(double latitude, double longitude, float distance,  string typeKeyWord)
        {
          //  Coordinate location = new Coordinate(10.762795, 106.682568);
            Coordinate location = new Coordinate(latitude, longitude);
            IList<PlaceInfo> resultPlaceInfos = new List<PlaceInfo>();
            typeKeyWord = StringHelper.GetSearchString(typeKeyWord, AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["abbr_file"]);
            PlaceTypeInfo type1 = PlaceTypeEx.GetPlaceTypeByDescription(typeKeyWord);
            resultPlaceInfos = PlaceEx.GetPlaceByTypeAround(type1.ID,
                                                            location, distance);

            List<PlaceInfo> lstService = (List<PlaceInfo>)resultPlaceInfos;
            Image img = mapHandler.ServiceAround(lstService, location.Latitude, location.Longitude);
            byte[] array = Helper.imageToByteArray(img);

            NearPlace result = new NearPlace();
            result.ListPlace = resultPlaceInfos;
            result.ArrayImage = array;

            return result;
        }

    }
}
